package com.ruoyi.material.controller;

import java.text.SimpleDateFormat;
import java.util.*;

import com.ruoyi.material.util.MapKeyComparator;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.BaseMaterial;
import com.ruoyi.material.service.IBaseMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 目录管理Controller
 * 
 * @author cyw
 * @date 2021-07-15
 */
@RestController
@RequestMapping("/material/manage")
public class BaseMaterialController extends BaseController
{
    @Autowired
    private IBaseMaterialService baseMaterialService;

    /**
     * 查询目录管理列表
     */
    @PreAuthorize("@ss.hasPermi('material:manage:list')")
    @GetMapping("/list")
    public AjaxResult list(BaseMaterial baseMaterial)
    {
        List<BaseMaterial> list = baseMaterialService.selectBaseMaterialList(baseMaterial);
        return AjaxResult.success(list);
    }

    /**
     * 导出目录管理列表
     */
    @PreAuthorize("@ss.hasPermi('material:manage:export')")
    @Log(title = "目录管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseMaterial baseMaterial)
    {
        List<BaseMaterial> list = baseMaterialService.selectBaseMaterialList(baseMaterial);
        ExcelUtil<BaseMaterial> util = new ExcelUtil<BaseMaterial>(BaseMaterial.class);
        return util.exportExcel(list, "目录管理数据");
    }

    /**
     * 获取目录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:manage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(baseMaterialService.selectBaseMaterialById(id));
    }

    /**
     * 新增目录管理
     */
    @PreAuthorize("@ss.hasPermi('material:manage:add')")
    @Log(title = "目录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseMaterial baseMaterial)
    {
        return toAjax(baseMaterialService.insertBaseMaterial(baseMaterial));
    }

    /**
     * 修改目录管理
     * 修改文件路径
     */
    @PreAuthorize("@ss.hasPermi('material:manage:edit')")
    @Log(title = "目录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseMaterial baseMaterial)
    {
//        return toAjax(baseMaterialService.updateBMFolderPcodeById(baseMaterial));
        return toAjax(baseMaterialService.updateBaseMaterial(baseMaterial));
    }

    /**
     * 删除目录管理
     */
    @PreAuthorize("@ss.hasPermi('material:manage:remove')")
    @Log(title = "目录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(baseMaterialService.deleteBaseMaterialByIds(ids));
    }

}
